const express = require("express");
const app = express();
const path = require('path')

//引入数据库连接文件
require("./db")


//引入外部路由
const addAdminRoute = require("./routes/addAdmin");
const adminListRoute = require("./routes/adminList");
const deleteAdminRoute = require('./routes/deleteAdmin')
const loginRoute = require('./routes/login')
const isLoginRoute = require('./routes/isLogin')
const logoutRoute = require('./routes/logout')
const addAdvRoute = require('./routes/addAdv')
const advListRoute = require('./routes/advList')
const advdeleteRoute = require('./routes/deleteAdv')
const getUpdateDataRoute = require('./routes/getUpdateData')
const updateAdvRoute = require('./routes/updateAdv')



//处理post请求addAdv的中间件,会在req上添加一个body属性,值是请求体参数
app.use(express.urlencoded());
app.use(express.json());

//暴露upload的文件
app.use('/upload',express.static(path.resolve(__dirname,'./upload')))

//使用路由
app.use(addAdminRoute)
app.use(adminListRoute)
app.use(deleteAdminRoute)
app.use(loginRoute)
app.use(isLoginRoute)
app.use(logoutRoute)
app.use(addAdvRoute)
app.use(advListRoute)
app.use(advdeleteRoute)
app.use(getUpdateDataRoute)
app.use(updateAdvRoute)

app.listen("8000", () => {
  console.log("服务器启动成功 http://127.0.0.1:8000");
})